﻿using System;
using System.Collections.Generic;
using System.Data.Common.CommandTrees;
using System.Data.Objects.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.InsuranceOrder;
using ZBJF.Warranty.Common.Enums.InsuranceWarranty;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.Udesk;


namespace ZBJF.Warranty.BLL
{
    public partial class Udesk_CallRecordService
    {
        public IQueryable<Udesk_CallRecord> GetPagingList(CallRecordModel model, out int total)
        {
            var expressionWhere = PredicateExtensions.True<Udesk_CallRecord>();
            if(!string.IsNullOrEmpty(model.User_name))
            {
                expressionWhere = expressionWhere.And(n => n.User_name.Contains(model.User_name));
            }
            if (!string.IsNullOrEmpty(model.Agent_nick_name))
            {
                expressionWhere = expressionWhere.And(n => n.Agent_nick_name.Contains(model.Agent_nick_name));
            }
            if (model.Call_start_atStart.HasValue)
            {
                expressionWhere = expressionWhere.And(n => n.Call_start_at>=model.Call_start_atStart);
            }
            if (model.Call_start_atEnd.HasValue)
            {
                expressionWhere = expressionWhere.And(n => n.Call_start_at<=model.Call_start_atEnd);
            }
            if (string.IsNullOrEmpty(model.iSorts))
            {
                model.iSorts = "Call_start_at desc";
            }
            return LoadPagerEntities<Udesk_CallRecord>(model.PageIndex, model.iDisplayLength, out total, expressionWhere, model.iSorts);
        }
        public Udesk_CallRecord LoadByID(int id)
        {
            return LoadEntities(o => o.ID == id).FirstOrDefault();
        }
    }
}
